package com.gm.wholesale.module.order.model;

import android.util.ArrayMap;

import com.gm.commonlib.base.baseBean.BaseListResp;
import com.gm.commonlib.base.baseBean.BaseResp;
import com.gm.commonlib.base.baseBean.DataResp;
import com.gm.commonlib.base.baseView.IBaseView;
import com.gm.commonlib.network.BaseHttpObserver;
import com.gm.commonlib.network.HttpClient;
import com.gm.commonlib.network.HttpServicesHolder;
import com.gm.wholesale.module.order.api.IOrderApi;
import com.gm.wholesale.module.order.bean.CreateAftersaleReq;
import com.gm.wholesale.module.order.bean.CreateOrderBean;
import com.gm.wholesale.module.order.bean.OrderDetailBean;
import com.gm.wholesale.module.order.bean.OrderRecmPriceBean;
import com.gm.wholesale.module.order.bean.ReviceMoneyReq;

import io.reactivex.Observable;

public class OrderModel {
    public static void createOrder(IBaseView iBaseView, CreateOrderBean data,
                                   BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.createOrder(data);
            }
        }, observer);
    }

    //修改订单
    public static void updateOrder(IBaseView iBaseView,long orderId, CreateOrderBean data,
                                   BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.updateOrder(orderId,data);
            }
        }, observer);
    }


    public static void getOrderDetail(IBaseView iBaseView,
                                      long orderId,
                                      BaseHttpObserver<DataResp<OrderDetailBean>> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, DataResp<OrderDetailBean>>() {
            @Override
            public Observable<DataResp<OrderDetailBean>> getHttpObservable(IOrderApi instance) {
                return instance.getOrderDetail(orderId);
            }
        }, observer);
    }

    // todo 获取用户常用的推荐价格
    public static void getOrderRecPrice(IBaseView iBaseView,
                                        ArrayMap<String, Object> data,
                                        BaseHttpObserver<DataResp<OrderRecmPriceBean>> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, DataResp<OrderRecmPriceBean>>() {
            @Override
            public Observable<DataResp<OrderRecmPriceBean>> getHttpObservable(IOrderApi instance) {
                return instance.getOrderPrice(data);
            }
        }, observer);
    }

    //订单详情收款
    public static void reviceMoney(IBaseView iBaseView,
                                        ReviceMoneyReq data,
                                        BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.orderToPay(data);
            }
        }, observer);
    }


    //创建售后单子
    public static void createAftersale(IBaseView iBaseView,
                                   long orderId,
                                   CreateAftersaleReq createAftersaleReq,
                                   BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.createAftersale(orderId,createAftersaleReq);
            }
        }, observer);
    }



    public static void refund(IBaseView iBaseView,
                                       long orderId,
                                       long aftersaleId,
                                       ArrayMap<String,Object> data,
                                       BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.refund(orderId,aftersaleId,data);
            }
        }, observer);
    }


    //订单收款
    public static void payOrder(IBaseView iBaseView,long orderId, ArrayMap<String,Object> data,
                                   BaseHttpObserver<BaseResp> observer) {
        HttpClient.sendRequest(iBaseView, new HttpServicesHolder<IOrderApi, BaseResp>() {
            @Override
            public Observable<BaseResp> getHttpObservable(IOrderApi instance) {
                return instance.payMoney(orderId,data);
            }
        }, observer);
    }


}
